<template>
  <div class="login">
    <el-form
      class="form"
      :model="form"
      :rules="rules"
      size="mini"
      ref="ruleForm"
      label-width="100px"
    >
      <el-form-item label="用户名" prop="username">
        <el-input style="width: 320px" v-model="form.username"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input style="width: 320px" v-model="form.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button class="btn" type="primary" size="mini" @click="login"
          >登录</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "Login",
  data() {
    return {
      form: {
        username: "",
        password: "",
      },

      rules: {
        username: [
          { required: true, message: "用户名不可为空", trigger: "blur" },
        ],
        password: [
          { required: true, message: "密码不可为空", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    login() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          // 登录成功后跳转到 school页面
          this.$router.replace("/layout");
        } else {
          return false;
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.login {
  box-sizing: border-box;
  height: 100%;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #34495e;
  .form {
    width: 500px;
    background-color: #2c3e50;
    padding-top: 20px;
    padding-right: 20px;
    border-radius: 5px;
    .btn {
      width: 100%;
      width: 320px;
    }
    ::v-deep label {
      color: #fff;
    }
  }
}
</style>
